package edu.yctc.weblog.utils;

import edu.yctc.weblog.entity.BlogDO;
import edu.yctc.weblog.entity.CommentDO;
import edu.yctc.weblog.entity.LinkDO;
import edu.yctc.weblog.enums.BlogDeleteStatus;
import edu.yctc.weblog.enums.LinkDeleteStatus;
import edu.yctc.weblog.vo.CommentVO;
import edu.yctc.weblog.vo.SaveBlogVO;
import edu.yctc.weblog.vo.SaveLinkVO;
import edu.yctc.weblog.vo.UpdateBlogVO;

/**
 * 
 * @className VOUtil
 * @description vo到do的防腐层
 * @author zyj
 * @date 2020年6月20日
 *
 */
public class VOUtil {

    public static BlogDO coverSaveBlogVO2BlogDO(SaveBlogVO saveBlogVO) {
        BlogDO blogDO = new BlogDO();
        blogDO.setTitle(saveBlogVO.getBlogTitle());
        blogDO.setSubUrl(saveBlogVO.getBlogSubUrl());
        blogDO.setCategoryId(saveBlogVO.getBlogCategoryId());
        blogDO.setTags(saveBlogVO.getBlogTags());
        blogDO.setContent(saveBlogVO.getBlogContent());
        blogDO.setCoverImage(saveBlogVO.getBlogCoverImage());
        blogDO.setStatus(saveBlogVO.getBlogStatus());
        blogDO.setIsEnableComment(saveBlogVO.getEnableComment());
        blogDO.setIsDeleted(BlogDeleteStatus.UNDELETED);
        blogDO.setViews(0L);
        return blogDO;
    }

    public static BlogDO coverUpdateBlogVO2BlogDO(UpdateBlogVO updateBlogVO) {
        BlogDO blogDO = new BlogDO();
        blogDO.setId(updateBlogVO.getBlogId());
        blogDO.setTitle(updateBlogVO.getBlogTitle());
        blogDO.setSubUrl(updateBlogVO.getBlogSubUrl());
        blogDO.setCategoryId(updateBlogVO.getBlogCategoryId());
        blogDO.setTags(updateBlogVO.getBlogTags());
        blogDO.setContent(updateBlogVO.getBlogContent());
        blogDO.setCoverImage(updateBlogVO.getBlogCoverImage());
        blogDO.setStatus(updateBlogVO.getBlogStatus());
        blogDO.setIsEnableComment(updateBlogVO.getEnableComment());
        blogDO.setIsDeleted(BlogDeleteStatus.UNDELETED);
        blogDO.setViews(0L);
        return blogDO;
    }

    public static LinkDO coverSaveLinkVO2LinkDO(SaveLinkVO saveLinkVO) {
        LinkDO linkDO = new LinkDO();
        linkDO.setType(saveLinkVO.getLinkType());
        linkDO.setRank(saveLinkVO.getLinkRank());
        linkDO.setName(saveLinkVO.getLinkName());
        linkDO.setUrl(saveLinkVO.getLinkUrl());
        linkDO.setDescription(saveLinkVO.getLinkDescription());
        linkDO.setIsDeleted(LinkDeleteStatus.UNDELETED);
        return linkDO;
    }

    public static CommentDO coverCommentVO2CommentDO(CommentVO commentVO) {
        CommentDO commentDO = new CommentDO();
        commentDO.setBlogId(commentVO.getBlogId());
        commentDO.setCommentator(commentVO.getCommentator());
        commentDO.setEmail(commentVO.getEmail());
        commentDO.setUrl(commentVO.getWebsiteUrl());
        commentDO.setComment(commentVO.getCommentBody());
        return commentDO;
    }

}
